import Vue from 'vue'
import VueRouter from 'vue-router'

// 解决多次点击同一个路由报错的问题(不影响使用)
// 原因：原因在于Vue-router在3.1之后把$router.push()方法改为了Promise。
//       所以假如没有回调函数，错误信息就会交给全局的路由错误处理，因此就会报上述的错误。
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

//安装插件
Vue.use(VueRouter)

const find = ()=> import('../views/Find/Find')
const profile = ()=>import('../views/Profile/Profile')
const cloud_village = ()=>import('../views/CloudVillage/CloudVillage')
const video =() =>import('../views/Video/Video')

const songlist =()=>import('../views/Find/ChildFind/SongList')
const mycollect =()=>import('../views/Profile/ChildProfile/MyCollect')
const profilecollectlist =()=>import('../views/Profile/ChildProfile/ProfileCollectList')
const profilecreatelist =()=>import('../views/Profile/ChildProfile/ProfileCreateList')
const login =()=>import('../components/content/login/Login')
const tellogin =()=>import('../components/content/login/TelLogin')
const rank =()=>import('../views/Rank/Rank')
const radio =()=>import('../views/Radio/Radio')
const singerclass = ()=>import('../views/SingerClass/SingerClass')
const dailyrecommand =()=>import('../components/content/dailyRecommand/DailyRecommand')
const search =()=>import('../views/Search/Search')
const songsheetsquare = ()=>import('../views/SongSheetSquare/SongSheetSquare')
const RadioClassification =()=>import('../views/Radio/ChildRadio/RadioClassification')
const RadioRank =()=>import('../views/Radio/ChildRadio/RadioRank')
const RadioPayGift =()=>import('../views/Radio/ChildRadio/RadioPayGift')
const PlayDetail =()=>import('../views/Player/ChildPlayer/PlayDetail')
const MailLogin =()=>import('../components/content/login/MailLogin')
const ADPage =()=>import('../views/ADPage/ADPage')



const routes = [
  {
    path:'',
    redirect:'/ADPage'  //重定向到find
  },
  {
    path: '/find',
    component:find,  //路径含有find 转到find'
  },
  {
    path:'/profile',
    component:profile,  //路径含有profile转到profile
    children:[
      {
        path:'',
        redirect:'create' //重定向-我创建的歌单
      },
      {
        path: 'create',
        component:profilecreatelist //我的-创建歌单
      },
      {
        path:'collect',
        component:profilecollectlist  //我的-收藏歌单
      }
    ]
  },
  {
    path: '/cloud_village',
    component:cloud_village,  //路径含有cloud_village转到cloud_village
   },
  {
    path: '/video',
    component:video,  //路径含有video转到video
  },
  {
    path: '/search',
    component:search,  //路径含有search跳转到search
  },
  {
    path: '/songlist/:id',
    component:songlist,
  },
  {
    path: '/mycollect',
    component:mycollect,
  },
  {
    path: '/login',
    component:login,
  },
  {
    path: '/login/tellogin',
    component:tellogin,
  },
  {
    path: '/rank',
    component:rank,
  },
  {
    path: '/radio',
    component:radio,
  },
  {
    path: '/singerClass',
    component:singerclass,
    children: [
      {
        path:'',
        redirect:'chinese' //重定向-华语
      },
      {
        path: 'chinese',  //华语
        children:[
          {
            path:'male',
          },
          {
            path:'female',
          },
          {
            path: 'others',
          }
        ]
      },
      {
        path: 'europe',  //欧美
        children:[
          {
            path:'male',
          },
          {
            path:'female',
          },
          {
            path: 'others',
          }
        ]
      },
      {
        path: 'japanese',  //日本
        children:[
          {
            path:'male',
          },
          {
            path:'female',
          },
          {
            path: 'others',
          }
        ]
      },
      {
        path: 'korea',  //韩国
        children:[
          {
            path:'male',
          },
          {
            path:'female',
          },
          {
            path: 'others',
          }
        ]
      },
      {
        path: 'others',  //其他
        children:[
          {
            path:'male',
          },
          {
            path:'female',
          },
          {
            path: 'others',
          }
        ]
      },

    ]
  },
  {
    path: '/dailyrecommand',
    component:dailyrecommand,
  },
  {
    path: '/songsheetsquare',
    component:songsheetsquare,
  },
  {
    path: '/Radio/RadioClassification',
    component:RadioClassification,
  },
  {
    path: '/Radio/RadioRank',
    component:RadioRank,
  },
  {
    path: '/Radio/RadioPayGift',
    component:RadioPayGift,
  },
  {
    path: '/PlayDetail',
    component:PlayDetail,
  },
  {
    path: '/login/MailLogin',
    component:MailLogin,
  },
  {
    path: '/ADPage',
    component:ADPage,
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
